#!/usr/bin/env python

import socket
import string

AD_PORT = 6000
MAX_CONS = 3

ad_list = [
	'ad 1',
	'ad 2',
	'ad 3',
]

next_ad = 0
max_ad = len(ad_list)



if __name__ == '__main__':
	s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	s.bind(('localhost', AD_PORT))
	s.listen(MAX_CONS)

	while 1:
		print 'waiting for new connections ...'
		(s2, address) = s.accept()
		print 'connected from', address
		
		# Send the ad
		s2.send(ad_list[next_ad])


		s2.close()
		next_ad += 1
		next_ad %= max_ad

